#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int t,n,m,l,lv,idx,ans;
int d[N],v[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n>>m>>l>>lv;
        for(int i=1;i<=N;i++){
            d[i]=0;v[i]=0;
        }
        ans=0;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>idx;
        }
        for(int i=1;i<=m;i++){
            cin>>idx;
        }
        for(int i=1;i<=n;i++){
            if(d[i]<=idx&&v[i]>lv) ans++;
        }
        cout<<ans<<' ';
        if(ans==0) cout<<m<<'\n';
        else cout<<m-1<<'\n';
    }
    return 0;
}
